<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>订单管理</title>
	<meta name="decorator" content="ani"/>
	<script type="text/javascript">
		var validateForm;
		var $table; // 父页面table表格id
		var $topIndex;//弹出窗口的 index
		function doSubmit(table, index){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
		  if(validateForm.form()){
			  $table = table;
			  $topIndex = index;
			  jp.loading();
			  $("#inputForm").submit();
			  return true;
		  }

		  return false;
		}

		$(document).ready(function() {
			validateForm = $("#inputForm").validate({
				submitHandler: function(form){
					jp.post("${ctx}/tms/torder/save",$('#inputForm').serialize(),function(data){
						if(data.success){
	                    	$table.bootstrapTable('refresh');
	                    	jp.success(data.msg);
	                    	jp.close($topIndex);//关闭dialog

	                    }else{
            	  			jp.error(data.msg);
	                    }
					})
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
	        $('#orderDate').datetimepicker({
				 format: "YYYY-MM-DD HH:mm:ss"
		    });
	        $('#pickDate').datetimepicker({
				 format: "YYYY-MM-DD HH:mm:ss"
		    });
		});
		
		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
			$(list+idx).find(".form_datetime").each(function(){
				 $(this).datetimepicker({
					 format: "YYYY-MM-DD HH:mm:ss"
			    });
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}
	</script>
</head>
<body class="bg-white">
		<form:form id="inputForm" modelAttribute="torder" action="${ctx}/tms/torder/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<table class="table table-bordered">
		   <tbody>
				<tr>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>订单类型：</label></td>
					<td class="width-35">
						<form:select path="type" class="form-control required">
							<form:option value="" label=""/>
							<form:options items="${fns:getDictList('order_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>订单编号：</label></td>
					<td class="width-35">
						<form:input path="code" htmlEscape="false" maxlength="64"    class="form-control required"/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">下单时间：</label></td>
					<td class="width-35">
						<p class="input-group">
							<div class='input-group form_datetime' id='orderDate'>
			                    <input type='text'  name="orderDate" class="form-control "  value="<fmt:formatDate value="${torder.orderDate}" pattern="yyyy-MM-dd HH:mm:ss"/>"/>
			                    <span class="input-group-addon">
			                        <span class="glyphicon glyphicon-calendar"></span>
			                    </span>
			                </div>						            
			            </p>
					</td>
					<td class="width-15 active"><label class="pull-right">订单状态：</label></td>
					<td class="width-35">
						<form:input path="status" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">提货时间：</label></td>
					<td class="width-35">
						<p class="input-group">
							<div class='input-group form_datetime' id='pickDate'>
			                    <input type='text'  name="pickDate" class="form-control "  value="<fmt:formatDate value="${torder.pickDate}" pattern="yyyy-MM-dd HH:mm:ss"/>"/>
			                    <span class="input-group-addon">
			                        <span class="glyphicon glyphicon-calendar"></span>
			                    </span>
			                </div>						            
			            </p>
					</td>
					<td class="width-15 active"><label class="pull-right">要求车型：</label></td>
					<td class="width-35">
						<form:select path="truckType" class="form-control ">
							<form:option value="" label=""/>
							<form:options items="${fns:getDictList('truck_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">是否需要装卸工：</label></td>
					<td class="width-35">
						<form:radiobuttons path="isLoad" items="${fns:getDictList('is_load')}" itemLabel="label" itemValue="value" htmlEscape="false" class="i-checks "/>
					</td>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>运输类型：</label></td>
					<td class="width-35">
						<form:select path="transportType" class="form-control required">
							<form:option value="" label=""/>
							<form:options items="${fns:getDictList('transport_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">是否需要回单：</label></td>
					<td class="width-35">
						<form:radiobuttons path="isReceipt" items="${fns:getDictList('is_receipt')}" itemLabel="label" itemValue="value" htmlEscape="false" class="i-checks "/>
					</td>
					<td class="width-15 active"><label class="pull-right">发货单位：</label></td>
					<td class="width-35">
						<form:input path="goodsCompany" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">发货联系人：</label></td>
					<td class="width-35">
						<form:input path="goodsContacts" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">发货联系人电话：</label></td>
					<td class="width-35">
						<form:input path="goodsPhone" htmlEscape="false" maxlength="64"    class="form-control  isTel"/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">提货地址：</label></td>
					<td class="width-35">
						<form:input path="pickAddress" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">提货联系人：</label></td>
					<td class="width-35">
						<form:input path="pickContacts" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">提货联系人电话：</label></td>
					<td class="width-35">
						<form:input path="pickPhone" htmlEscape="false" maxlength="64"    class="form-control  isTel"/>
					</td>
					<td class="width-15 active"><label class="pull-right">里程：</label></td>
					<td class="width-35">
						<form:input path="miles" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">代收货款：</label></td>
					<td class="width-35">
						<form:input path="agencyPayment" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">代收货款手续费：</label></td>
					<td class="width-35">
						<form:input path="agencyCharge" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">回单份数：</label></td>
					<td class="width-35">
						<form:input path="receiptAmount" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">回单返回要求：</label></td>
					<td class="width-35">
						<form:select path="receiptRequire" class="form-control ">
							<form:option value="" label=""/>
							<form:options items="${fns:getDictList('receipt_require')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">装卸要求：</label></td>
					<td class="width-35">
						<form:select path="loadRequire" class="form-control ">
							<form:option value="" label=""/>
							<form:options items="${fns:getDictList('load_require')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
					<td class="width-15 active"><label class="pull-right">装卸费：</label></td>
					<td class="width-35">
						<form:input path="loadCharge" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">手推车服务：</label></td>
					<td class="width-35">
						<form:select path="cart" class="form-control ">
							<form:option value="" label=""/>
							<form:options items="${fns:getDictList('cart')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
					<td class="width-15 active"><label class="pull-right">声明货物价值：</label></td>
					<td class="width-35">
						<form:input path="goodsValue" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">保险费：</label></td>
					<td class="width-35">
						<form:input path="insuranceCharge" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">运输费：</label></td>
					<td class="width-35">
						<form:input path="transportCharge" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">装卸费合计：</label></td>
					<td class="width-35">
						<form:input path="totalLoadCharge" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">费用合计：</label></td>
					<td class="width-35">
						<form:input path="totaCharge" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">起始区域：</label></td>
					<td class="width-35">
						<form:input path="startArea" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">目的区域：</label></td>
					<td class="width-35">
						<form:input path="endArea" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">送货地址：</label></td>
					<td class="width-35">
						<form:input path="sendAddress" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">送货联系人：</label></td>
					<td class="width-35">
						<form:input path="sendContacts" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">送货电话：</label></td>
					<td class="width-35">
						<form:input path="sendPhone" htmlEscape="false" maxlength="64"    class="form-control  isTel"/>
					</td>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>备注信息：</label></td>
					<td class="width-35">
						<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="64"    class="form-control required"/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">指定承运商：</label></td>
					<td class="width-35">
						<form:input path="appointCarriers" htmlEscape="false" maxlength="64"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">总重量：</label></td>
					<td class="width-35">
						<form:input path="totalWeight" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">总方数：</label></td>
					<td class="width-35">
						<form:input path="totalVolume" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"></td>
		   			<td class="width-35" ></td>
		  		</tr>
		 	</tbody>
		</table>
		<div class="tabs-container">
            <ul class="nav nav-tabs">
				<li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">收货地址：</a>
                </li>
				<li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">货物：</a>
                </li>
            </ul>
            <div class="tab-content">
				<div id="tab-1" class="tab-pane fade in  active">
			<a class="btn btn-white btn-sm" onclick="addRow('#orderAddressList', orderAddressRowIdx, orderAddressTpl);orderAddressRowIdx = orderAddressRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
			<table class="table table-striped table-bordered table-condensed">
				<thead>
					<tr>
						<th class="hide"></th>
						<th>收货地址</th>
						<th>收货联系人</th>
						<th>收货联系人电话</th>
						<th>备注信息</th>
						<th width="10">&nbsp;</th>
					</tr>
				</thead>
				<tbody id="orderAddressList">
				</tbody>
			</table>
			<script type="text/template" id="orderAddressTpl">//<!--
				<tr id="orderAddressList{{idx}}">
					<td class="hide">
						<input id="orderAddressList{{idx}}_id" name="orderAddressList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="orderAddressList{{idx}}_delFlag" name="orderAddressList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>
					
					<td>
						<input id="orderAddressList{{idx}}_receiveAddress" name="orderAddressList[{{idx}}].receiveAddress" type="text" value="{{row.receiveAddress}}" maxlength="64"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="orderAddressList{{idx}}_receiveContacts" name="orderAddressList[{{idx}}].receiveContacts" type="text" value="{{row.receiveContacts}}" maxlength="64"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="orderAddressList{{idx}}_receivePhone" name="orderAddressList[{{idx}}].receivePhone" type="text" value="{{row.receivePhone}}" maxlength="64"    class="form-control  isTel"/>
					</td>
					
					
					<td>
						<textarea id="orderAddressList{{idx}}_remarks" name="orderAddressList[{{idx}}].remarks" rows="4" maxlength="255"    class="form-control ">{{row.remarks}}</textarea>
					</td>
					
					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#orderAddressList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
					</td>
				</tr>//-->
			</script>
			<script type="text/javascript">
				var orderAddressRowIdx = 0, orderAddressTpl = $("#orderAddressTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
				$(document).ready(function() {
					var data = ${fns:toJson(torder.orderAddressList)};
					for (var i=0; i<data.length; i++){
						addRow('#orderAddressList', orderAddressRowIdx, orderAddressTpl, data[i]);
						orderAddressRowIdx = orderAddressRowIdx + 1;
					}
				});
			</script>
			</div>
				<div id="tab-2" class="tab-pane fade">
			<a class="btn btn-white btn-sm" onclick="addRow('#orderDetailList', orderDetailRowIdx, orderDetailTpl);orderDetailRowIdx = orderDetailRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
			<table class="table table-striped table-bordered table-condensed">
				<thead>
					<tr>
						<th class="hide"></th>
						<th>货物名称</th>
						<th>件数</th>
						<th>重量（KG）</th>
						<th>体积（M3）</th>
						<th>包装</th>
						<th>备注信息(尺寸规格等)</th>
						<th width="10">&nbsp;</th>
					</tr>
				</thead>
				<tbody id="orderDetailList">
				</tbody>
			</table>
			<script type="text/template" id="orderDetailTpl">//<!--
				<tr id="orderDetailList{{idx}}">
					<td class="hide">
						<input id="orderDetailList{{idx}}_id" name="orderDetailList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="orderDetailList{{idx}}_delFlag" name="orderDetailList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>
					
					<td>
						<input id="orderDetailList{{idx}}_goodsName" name="orderDetailList[{{idx}}].goodsName" type="text" value="{{row.goodsName}}" maxlength="64"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="orderDetailList{{idx}}_goodsAmount" name="orderDetailList[{{idx}}].goodsAmount" type="text" value="{{row.goodsAmount}}" maxlength="64"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="orderDetailList{{idx}}_weight" name="orderDetailList[{{idx}}].weight" type="text" value="{{row.weight}}" maxlength="64"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="orderDetailList{{idx}}_volume" name="orderDetailList[{{idx}}].volume" type="text" value="{{row.volume}}" maxlength="64"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="orderDetailList{{idx}}_packaging" name="orderDetailList[{{idx}}].packaging" type="text" value="{{row.packaging}}" maxlength="64"    class="form-control "/>
					</td>
					
					
					<td>
						<textarea id="orderDetailList{{idx}}_remarks" name="orderDetailList[{{idx}}].remarks" rows="4" maxlength="255"    class="form-control ">{{row.remarks}}</textarea>
					</td>
					
					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#orderDetailList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
					</td>
				</tr>//-->
			</script>
			<script type="text/javascript">
				var orderDetailRowIdx = 0, orderDetailTpl = $("#orderDetailTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
				$(document).ready(function() {
					var data = ${fns:toJson(torder.orderDetailList)};
					for (var i=0; i<data.length; i++){
						addRow('#orderDetailList', orderDetailRowIdx, orderDetailTpl, data[i]);
						orderDetailRowIdx = orderDetailRowIdx + 1;
					}
				});
			</script>
			</div>
		</div>
		</div>
		</form:form>
</body>
</html>